﻿using System;
using System.Net;

namespace socketlib_basic
{
    class DNS
    {
        /// <summary>
        /// resolve ip addres
        /// </summary>
        /// <param name="ip"></param>
        public static void Resolve(string hostname)
        {
	        try
	        {
                IPHostEntry iphost = Dns.GetHostEntry(hostname);
                IPAddress[] address = iphost.AddressList;
                String[] alias = iphost.Aliases;

                Console.WriteLine("Host name : " + iphost.HostName);
                
                Console.WriteLine("\nAliases :");
                for (int index = 0; index < alias.Length; index++)
                {
                    Console.WriteLine(alias[index]);
                }

                Console.WriteLine("\nIP address list : ");
                for (int index = 0; index < address.Length; index++)
                {
                    Console.WriteLine(address[index]);
                }

	        }
	        catch(Exception ex)
	        {
		        Console.WriteLine("Unable to process the request because " +
		            "the following problem occurred:\n" + ex.Message, "Exception occurred");
        		
	        }
        }

        public static void RunTest(string ip)
        {
            Resolve(ip);
        }
    }
}